package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;

import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@Api(tags = "护理计划接口")
@Slf4j
@RequestMapping("/nursing")
@RestController
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;


    @ApiOperation(value = "护理计划分页查询")
    @GetMapping("/plan/search")
    public ResponseResult<PageResponse<NursingPlanVo>> paramQuery(
            @ApiParam(value = "护理计划名称") String name,
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @ApiParam(value = "状态 0为禁用,1为启用") Integer status) {
        PageResponse<NursingPlanVo> pageResponseResult = nursingPlanService.paramQuery(name, pageNum, pageSize, status);
        log.info("查看count:{}", Arrays.toString(pageResponseResult.getRecords().toArray(new NursingPlanVo[0])));
        return ResponseResult.success(pageResponseResult);
    }

    @ApiOperation(value = "新增护理计划")
    @PostMapping("/plan")
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto dto) {
        nursingPlanService.addNursingPlan(dto);
        return ResponseResult.success();
    }

    @ApiOperation(value = "查询所有护理计划")
    @GetMapping("/plan")
    public ResponseResult<NursingPlanVo> findAllNursingPlan() {
        List<NursingPlanVo> vo = nursingPlanService.findAllNursingPlan();
        return ResponseResult.success(vo);
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping("/plan/{id}")
    public ResponseResult<NursingPlanVo> selectById(@PathVariable Integer id) {
        NursingPlanVo vo = nursingPlanService.selectById(id);
        return ResponseResult.success(vo);
    }

    @ApiOperation(value = "修改")
    @PutMapping("/plan/{id}")
    public ResponseResult modifyNursingPlan(@PathVariable Long id,
                                            @RequestBody NursingPlanDto dto) {
        nursingPlanService.modifyNursingPlan(id, dto);
        return ResponseResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/plan/{id}")
    public ResponseResult deleteNursingPlan(@PathVariable Long id) {
        nursingPlanService.deleteNursingPlan(id);
        return ResponseResult.success();
    }

    @ApiOperation(value = "启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult nursingPlanStatus(@PathVariable Long id,
                                            @PathVariable Integer status) {
        nursingPlanService.nursingPlanStatus(id , status);

        return  ResponseResult.success();
    }

}
